<template>
  <div>
    <div id="c2" class="o-echarts"></div>
  </div>
</template>

<script>

import request from "../utils/request";

import {eventBus} from '../main'

export default {
  name: 'province',
  data() {
    return {
      dataList: [],
      dataName: [],
      dataConfirm: [],
      dataHeal: [],
      echartObj: null,
      name: ''
    }
  },
  created() {
    eventBus.$on('name', (message) => {
      this.name = message
      this.getData(message);
    })
  },
  mounted() {
  },
  methods: {
    getData(message) {
      request.get('/cov/c2' + '?name=' + message).then(res => {
        this.dataList = res
        this.dataName = []
        this.dataConfirm = []
        this.dataHeal = []
        for (let i = 0; i < this.dataList.length; i++) {
          this.dataName[i] = this.dataList[i].city
          this.dataConfirm[i] = this.dataList[i].confirm
          this.dataHeal[i] = this.dataList[i].heal
        }
        console.log(this.dataName)
        // 获取某以省份下的市级数据清单
        this.dataList = res
        this.initMap()
      })
    },
    initMap() {
      var chartDom = document.getElementById('c2');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '市级信息数据',
          textStyle: {
            color: "#00ff15"
          }
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          textStyle: {
            color: "#fff"
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0.01],
          axisLine: {
            lineStyle: {
              color: '#fff',
              width: 1,//这里是为了突出显示加上的
            }
          }
        },
        yAxis: {
          type: 'category',
          data: this.dataName,
          axisLine: {
            lineStyle: {
              color: '#fff',
              width: 1,//这里是为了突出显示加上的
            }
          }
        },
        series: [
          {
            name: '目前确诊人数',
            type: 'bar',
            data: this.dataConfirm
          },
          {
            name: '治愈人数',
            type: 'bar',
            data: this.dataHeal
          }
        ]
      };

      myChart.setOption(option);
    }
  }
}
</script>
<style scoped>
.o-echarts {
  height: 400px;
  width: 600px;
  margin: auto;
}
</style>
